var mongodb = require("mongodb");
var db = require("../mougodb/db");

module.exports.postAdd = function(req,res){
  // 接收前端传过来的值
  var obj = req.body;
  
  db.insertOne(res,obj,"day1117",function(err,result,db1){
    if(err){
      res.send({code:404,msg:"添加失败"});
    }else{
      res.send({code:200,msg:"添加成功"});
      db1.close();
    }
  })
}

module.exports.getShow = function(req,res){

  db.find(res,{},"day1117",function(err,result,db1){
    if(err){
      res.send({code:404,msg:"渲染失败"});
    }else{
      res.send({code:200,msg:"渲染成功",info:result});
      db1.close();
    }
  })
}

module.exports.getDel = function(req,res){
  var id = {
    _id : mongodb.ObjectId(req.query.id)
  }
  db.deleteOne(res,id,"day1117",function(err,result,db1){
    if(err){
      res.send({code:404,msg:"删除失败"});
    }else{
      res.send({code:200,msg:"删除成功"});
      db1.close();
    }
  })
}

